/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package es.unavarra.mti.iws.logic.undoredo;

import es.unavarra.mti.iws.logic.editor.Selectable;
import es.unavarra.mti.iws.model.Model;
import java.util.List;


/**
 *
 * @author Asier
 */
public class DeleteEntries implements UndoRedoOperation{
    private final Model container;
    private Selectable[] entries;

    public DeleteEntries(Model model, List<Selectable> list) {
        this.container = model;
        synchronized(list){
            int size = list.size();
            entries = new Selectable[size];
            for(int i = 0; i <size; i++){
                entries[i] = list.get(i);
            }
        }
    }

    public void undo() {
        synchronized(container){
            for (int i = entries.length-1; i >=0 ; i--) {
                container.add(entries[i]); // indexes are not important
            }
        }
    }

    public void redo() {
        synchronized(container){
            for(int i = 0; i < entries.length; i++){
                container.remove(entries[i]);
            }
        }
    }

}
